import * as AWS from "aws-sdk"; export async function uploadImage(event, context, callback) { const { name, image } = event.formData; const buffer = Buffer.from(image, "binary"); await new AWS.S3().putObject({ Bucket: "images", Key: name, Body: buffer }).promise(); resize({ srcData: buffer, format: "jpeg", width: 100 }, (err, stdout, stderr) => { if (err) { callback(err); return; } const data = Buffer.from(stdout, "binary"); rp({ url: `https://api.com/v1/thumbnails/${name}`, method: "put", formData: { name, data }, headers: { "content-type": "multipart/form-data" } }).then(() => { callback(null, { message: "Succeeded" }); }).catch(err => { throw err; }); }); } Serverless program must be complicated and error-prone even if you believe what you want is simple Copyright 2019 FUJITSU LABORATORIES LTD. api.com images API Gateway uploadImage Node.js modules AWS Cloud IAM 8